package com.example.easyexcel.converters;


import com.alibaba.excel.converters.longconverter.LongStringConverter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;

import java.text.ParseException;

/**
 * easyexcel自带的转换类 忽略了excel表格自动适应带来的隐式转换
 */
public class LongStrConverter extends LongStringConverter {

    @Override
    public Long convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty,
                                  GlobalConfiguration globalConfiguration) throws ParseException {
        if(cellData.getStringValue()==null){
            return cellData.getNumberValue().longValue();
        }else{
            return NumberUtils.parseLong(cellData.getStringValue(), contentProperty);
        }
    }

}
